package servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;


/*
* 响应数据
* 1.getWriter   字符输出流（输出字符串）
* 2.getOutputStream()  字节输出流（输出一切数据）*/
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/s01")
public class servlet01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取字符流输出
        PrintWriter out = response.getWriter();
        //输出数据
        out.write("hello");

        //获取字节流
        ServletOutputStream sos = response.getOutputStream();
        //输出字节流
        sos.write("hello".getBytes("UTF-8"));

        sos.close();
        //两种流不能同时使用，同时使用会报错
    }
}
